/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.hycreate.platform.modules.crm.todaycustomer;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.hycreate.platform.common.config.Global;
import com.hycreate.platform.common.persistence.Page;
import com.hycreate.platform.common.utils.StringUtils;
import com.hycreate.platform.common.web.BaseController;
import com.hycreate.platform.modules.sys.utils.UserUtils;

/**
 * 今日的客户Controller
 * @author zzf
 * @version 2016-12-03
 */
@Controller
@RequestMapping(value = "${adminPath}/crm/todaycustomer/todayCalendar")
public class TodayCalendarController extends BaseController {

	@Autowired
	private TodayCalendarService todayCalendarService;
	
	@ModelAttribute
	public TodayCalendar get(@RequestParam(required=false) String id) {
		TodayCalendar entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = todayCalendarService.get(id);
		}
		if (entity == null){
			entity = new TodayCalendar();
		}
		return entity;
	}
	
	@RequiresPermissions("todaycustomer:todayCalendar:view")
	@RequestMapping(value = {"list", ""})
	public String list(TodayCalendar todayCalendar, HttpServletRequest request, HttpServletResponse response, Model model) {
		 String operateMan= UserUtils.getUser().getId();
		todayCalendar.setOperateMan(operateMan);
		Page<TodayCalendar> page = todayCalendarService.findPage(new Page<TodayCalendar>(request, response), todayCalendar); 
		model.addAttribute("page", page);
		return "modules/crm/workbench/todayCalendarList";
	}

	@RequiresPermissions("todaycustomer:todayCalendar:view")
	@RequestMapping(value = "form")
	public String form(TodayCalendar todayCalendar, Model model) {
		model.addAttribute("todayCalendar", todayCalendar);
		return "modules/crm/workbench/todayCalendarForm";
	}
 
	
	@RequestMapping(value = "status")
	public String status(String content,String Calendarid,HttpServletRequest request, HttpServletResponse response) {
		TodayCalendar todayCalendar =new TodayCalendar();
		
		todayCalendar.setContent(content);
		todayCalendar.setStatus("已完成");
		todayCalendar.setId(Calendarid);
		
		todayCalendarService.updatestatus(todayCalendar);
		
		return "modules/crm/workbench/todayCalendarForm";
	}
	
	@RequiresPermissions("todaycustomer:todayCalendar:edit")
	@RequestMapping(value = "save")
	public String save(TodayCalendar todayCalendar, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, todayCalendar)){
			return form(todayCalendar, model);
		}
		todayCalendarService.save(todayCalendar);
		addMessage(redirectAttributes, "保存客户成功");
		return "redirect:"+Global.getAdminPath()+"/crm/workbench/todayCalendar/?repage";
	}
	
	@RequiresPermissions("todaycustomer:todayCalendar:edit")
	@RequestMapping(value = "delete")
	public String delete(TodayCalendar todayCalendar, RedirectAttributes redirectAttributes) {
		todayCalendarService.delete(todayCalendar);
		addMessage(redirectAttributes, "删除客户成功");
		return "redirect:"+Global.getAdminPath()+"/crm/workbench/todayCalendar/?repage";
	}

}